<template>
  <div>
  <el-table
      :data="tableData"
      border
      style="width: 100%">
    <el-table-column
        fixed
        prop="empno"
        label="编号"
    >
    </el-table-column>
    <el-table-column
        prop="ename"
        label="姓名"
    >
    </el-table-column>
    <el-table-column
        prop="job"
        label="岗位"
    >
    </el-table-column>
    <el-table-column
        prop="mgr"
        label="领导编号"
    >
    </el-table-column>
    <el-table-column
        prop="hiredate"
        label="入职日期"
    >
    </el-table-column>
    <el-table-column
        prop="sal"
        label="薪水"
    >
    </el-table-column>
    <el-table-column
        prop="dept.dname"
        label="部门"
    >
    </el-table-column>
    <el-table-column
        fixed="right"
        label="操作"
        width="100">
      <template slot-scope="scope">
        <el-button @click="del(scope.row)" type="text" size="small">删除</el-button>
        <el-button type="text" size="small">编辑</el-button>
      </template>
    </el-table-column>
  </el-table>
    <div>
      <div class="block">
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pagedata.current"
            :page-sizes="[2,4,6,8]"
            :page-size="pagedata.size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="pagedata.total">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import qs from 'qs'
export default {
  data() {
    return {
      tableData: [],
      pagedata:{
        current: 1,
        total: 0,
        size:4
      }
    }
  },
  methods:{
    querydata(){
      this.$axios.post('/emp',qs.stringify(this.pagedata)).then(res=>{
        this.tableData=res.data.data.records
        this.pagedata.total=res.data.data.total
      })
    },
    handleSizeChange(val) {
      this.pagedata.size=val;
      this.querydata()
    },
    handleCurrentChange(val) {
     this.pagedata.current=val;
     this.querydata()
    },
    del(val){
     var id=val.empno
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$axios.delete('/emp/'+id).then(res=>{
              if (res.data.data==1){
                this.$message({
                      type: 'success',
                      message: '删除成功!'
                    },
                    this.querydata()
                )
              }else {
                this.$message({
                  type: 'error',
                  message: '删除失败'
                });
              }
            }
        );
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    }
  },
  created() {
    this.querydata()
  }
}
</script>